package com.gljx.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gljx.constant.ActivitiKey;
import com.gljx.util.ActitiviUtil;
import com.gljx.web.Entity.TimingChargeEntry;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.dao.TimingChargeEntryMapper;
import com.gljx.web.dao.TimingChargeMapper;
import com.gljx.web.service.TimingChargeEntryService;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class TimingChargeEntryServiceImpl extends CommonDao implements TimingChargeEntryService{
	
	@Autowired
	private TimingChargeEntryMapper timingChargeEntryMapper;
	
	@Autowired
	private TimingChargeMapper timingChargeMapper;
	
	
	public List<TimingChargeEntry> queryTimingChargeEntry(String fparentId, String studentName, String cfidcardno,
			String cftjr) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("v_fparentid", fparentId);
	       paramMap.put("v_studentName", studentName);
	       paramMap.put("v_cfidcardno", cfidcardno);
	       paramMap.put("v_cftjr",cftjr);		
	       paramMap.put("v_cursor", oracle.jdbc.OracleTypes.CURSOR);	
	       this.getSqlSession().select("com.gljx.web.dao.TimingChargeEntryMapper.selectTimingChargeEntry", paramMap, null);
	       @SuppressWarnings("unchecked")
	       List<TimingChargeEntry> timingChargeEntrys = (List<TimingChargeEntry>) paramMap.get("v_cursor");
	       return timingChargeEntrys;
	}

	@Override
	public List<TimingChargeEntry> queryTrainChargeEntrysByFparentId(String fparentId) {
		return timingChargeEntryMapper.selectTimingChargeEntrysByFparentId(fparentId);
	}

	/**
	 * 实现删除单据
	 */
	@Override
	public void deleteTranChargeByFid(String[] deleteId, String fid,String[] fnumber,String fnumber2) {
		ActitiviUtil au = new ActitiviUtil();
		if(fid == null){
			for (int i = 0; i < deleteId.length; i++) {
				au.deleteTask(ActivitiKey.PUBLIC_PROCESS, fnumber[i]);
				timingChargeEntryMapper.deleteByFparentid(deleteId[i]);
				timingChargeMapper.deleteByPrimaryKey(deleteId[i]);
			}
		}else{
			au.deleteTask(ActivitiKey.PUBLIC_PROCESS, fnumber2);
			timingChargeEntryMapper.deleteByFparentid(fid);
			timingChargeMapper.deleteByPrimaryKey(fid);
		}
	}

	@Override
	public List<TimingChargeEntry> selectTimingChargeExcel(String studentName, String cfidcardno, String cftjr, String beginTime, String endTime, String companyId) {
		Map<String, String> map = new HashMap<>();
		map.put("studentName", studentName);
		map.put("cfidcardno", cfidcardno);
		map.put("cftjr", cftjr);
		map.put("beginTime", beginTime);
		map.put("endTime", endTime);
		map.put("companyId", companyId);
		return timingChargeEntryMapper.selectTimingChargeExcel(map);
	}

}
